import ReactDOM from "react-dom/client";
import { RouterProvider } from "react-router-dom";
import { AliveScope } from "react-activation";
import { Dialog } from "@nutui/nutui-react";
// @ts-ignore
import { registerSW } from "virtual:pwa-register";

import { optimizeSafari } from "@/utils/optimize";

import router from "@/router";

import "@nutui/nutui-react/dist/style.css";
import "@/styles/optimize.less";
import "@/styles/common.less";

// PWA 手动更新
const updateSW = registerSW({
  onNeedRefresh() {
    Dialog.alert({
      title: "更新",
      content: "发现新版本！点击立即更新，体验最新版本",
      noCancelBtn: true,
      okText: "立即更新",
      onOk() {
        updateSW(true);
      },
    });
  },
});

// js优化 safari 反人类的体验
optimizeSafari();

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <AliveScope>
    <RouterProvider router={router} />
  </AliveScope>
);
